package com.gitee.booting.dspi.example.provider;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.gitee.booting.dspi.Dspi;
import com.gitee.booting.dspi.example.api.IHello;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Dspi(names = {"demo"})
public class DemoHello implements IHello {
    @Autowired
    private NacosDiscoveryProperties properties;

    @Override
    public String hello() {
        return "Hello world!";
    }

    @Override
    public Map<String, String> metadata() {
        return properties.getMetadata();
    }

    @Override
    public Map<String, String> metadata(Map<String, String> whatever) {
        Map<String, String> r = new HashMap<>(properties.getMetadata());
        if (whatever != null) {
            r.putAll(whatever);
        }
        return r;
    }
}
